//
//  PpSetCentViewController.swift
//  Palmpilot
//
//  Created by 杨伟毅 on 2018/10/20.
//  Copyright © 2018年 杨伟毅. All rights reserved.
//

import UIKit

class PpSetCentViewController: PpBaseViewController,UITableViewDelegate,UITableViewDataSource {
    let setBaseView = UITableView.init(frame: ZCGRECT(x: 0, y: 0, width: SCREEN_width, height: SCREEN_HEIGHT-TopHeight), style: .grouped)
    let imageArr = [["feedback"],["share","about"],["privacy"]]
    let titleArr =  [[PpLanguageSwitchTool.getString(key: "Feedback")],[PpLanguageSwitchTool.getString(key: "Sharing software"),PpLanguageSwitchTool.getString(key: "About us")],[PpLanguageSwitchTool.getString(key: "Privacy")]]
    
    override func viewWillAppear(_ animated: Bool) {
        self.title = PpLanguageSwitchTool.getString(key: "More Settings")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor  = .white
        setBaseView.delegate = self
        setBaseView.dataSource = self
        setBaseView.register(UINib.init(nibName: "PpSetTableViewCell", bundle: Bundle.main), forCellReuseIdentifier: "PpSetTableViewCell")
//        setBaseView.separatorStyle = .none
        setBaseView.estimatedRowHeight =  90
        self.view.addSubview(setBaseView)
        PpBaseTool.insetTableViewAndUIViewController(baseView: setBaseView, baseVC: self)
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 || section == 2 {
            return 1
        }else{
            return 2
        }
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let baseCell:PpSetTableViewCell? = tableView.dequeueReusableCell(withIdentifier: "PpSetTableViewCell") as? PpSetTableViewCell
        baseCell?.baseImageView.image = UIImage.init(named: imageArr[indexPath.section][indexPath.row])?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        baseCell?.baseLabel.text = titleArr[indexPath.section][indexPath.row]
        baseCell?.selectionStyle = .none
        return baseCell!
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 10
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 90
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch(indexPath.section){
        case 0:
            self.navigationController?.pushViewController(PpFeedBackVC(), animated: true)
            break
        case 1:
            if indexPath.row == 0{
                let shareView = UIActivityViewController.init(activityItems: [PpLanguageSwitchTool.getString(key: "shareTips"),URL(string: "https://itunes.apple.com/cn/app/id1439884545")!,UIImage(named: "logoa") as Any], applicationActivities: nil)
                shareView.excludedActivityTypes = [.print,.copyToPasteboard,.assignToContact,.saveToCameraRoll,.addToReadingList,.airDrop]
                self.present(shareView, animated: true, completion: nil)
            }else{
                let showAlertVC = UIAlertController.init(title: PpLanguageSwitchTool.getString(key: "alertTitle"), message: PpLanguageSwitchTool.getString(key: "suporetEmail"), preferredStyle: .alert)
                let sureAction = UIAlertAction.init(title: PpLanguageSwitchTool.getString(key: "sure"), style: .cancel) { (action) in
                    
                }
                showAlertVC.addAction(sureAction)
                self.present(showAlertVC, animated: true, completion: nil)
                
            }
            break
        case 2:
            self.navigationController?.pushViewController(PpPrivceViewController(), animated: true)
            break
        default:
            break
        }
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
